<?php

namespace App\Admin\Controllers;

use App\Model\Order;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class OrderController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '订单列表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Order);

        $grid->column('id', __('Id'));
        $grid->column('order_sn', __('Order sn'));
        $grid->column('total_price', __('Total price'));
        $grid->column('remark', __('Remark'));
        $grid->column('shopping_no', __('Shopping no'));
        $grid->column('pay_at', __('Pay at'));
        $grid->column('buy_name', __('Buy name'));
        $grid->column('address', __('Address'));
        $grid->column('status', __('Status'));
        $grid->column('created_at', __('Created at'));

        $grid->disableCreateButton();

        $grid->filter(function (/** @var Grid\Filter $filter */$filter) {
            $filter->disableIdFilter();
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Order::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('order_sn', __('Order sn'));
        $show->field('total_price', __('Total price'));
        $show->field('goods_price', __('Goods price'));
        $show->field('shopping_price', __('Shopping price'));
        $show->field('status', __('Status'));
        $show->field('remark', __('Remark'));
        $show->field('shopping_no', __('Shopping no'));
        $show->field('pay_at', __('Pay at'));
        $show->field('out_trade_no', __('Out trade no'));
        $show->field('buy_name', __('Buy name'));
        $show->field('address', __('Address'));
        $show->field('zip_code', __('Zip code'));
        $show->field('country', __('Country'));
        $show->field('city', __('City'));
        $show->field('email', __('Email'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Order);

        $form->text('order_sn', __('Order sn'));
        $form->decimal('total_price', __('Total price'))->default(0.00);
        $form->decimal('goods_price', __('Goods price'))->default(0.00);
        $form->decimal('shopping_price', __('Shopping price'))->default(0.00);
        $form->switch('status', __('Status'));
        $form->text('remark', __('Remark'));
        $form->text('shopping_no', __('Shopping no'));
        $form->datetime('pay_at', __('Pay at'))->default(date('Y-m-d H:i:s'));
        $form->text('out_trade_no', __('Out trade no'));
        $form->text('buy_name', __('Buy name'));
        $form->text('address', __('Address'));
        $form->text('zip_code', __('Zip code'));
        $form->text('country', __('Country'));
        $form->text('city', __('City'));
        $form->email('email', __('Email'));

        return $form;
    }
}
